package com.parking.status.sync.netty.client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by Administrator on 2015/9/16.
 */
public class WholeFrameEncoder extends LengthFieldPrepender {

    public WholeFrameEncoder() {
        super(1, 2, true);
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
        int i = msg.readableBytes();
        byte[] head = new byte[]{(byte)0xAA, (byte)0xA5};
        out.writeBytes(head);

        i = msg.readableBytes();
        super.encode(ctx, msg, out);

    }
}